package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.service.DamageListGoodsService;
import com.atguigu.jxc.service.DamageListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

//商品报损
@RestController
@RequestMapping("/damageListGoods")
public class DamageListGoodsController{

    @Autowired
    private DamageListGoodsService damageListGoodsService;

    @Autowired
    private DamageListService damageListService;

    //http://localhost:8080/damageListGoods/save?damageNumber=BS1605766644460
    //保存报损单  damageListGoodsStr  商品类别信息
    @PostMapping("/save")
    public ServiceVO save(DamageList damageList, String damageListGoodsStr, HttpSession session){
        try {
            damageListGoodsService.save(damageList,damageListGoodsStr,session);
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE, ErrorCode.PARA_TYPE_ERROR_MESS);
        }
    }

    //http://localhost:8080/damageListGoods/list
    //报损单查询 ：String  sTime（开始时间）, String  eTime（结束时间）
    @PostMapping("/list")
    public Map<String,Object> list(String  sTime,String  eTime){
        return damageListService.list(sTime,eTime);
    }

    //http://localhost:8080/damageListGoods/goodsList
    //查询报损单商品信息 Integer damageListId（报损单Id）
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer damageListId){
        return damageListGoodsService.goodsList(damageListId);
    }


}


